package com.neeraj.SharingArtifacts;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SplashScreen extends Activity implements OnClickListener{
	private long ms=0;
	private long splashTime=5000;
	private boolean splashActive = true;
	private boolean paused=false;
	private Thread mSplashThread;
	private boolean isButtonClicked = false;
	Button beginTour, visitPlaces;
	 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
		beginTour = (Button)findViewById(R.id.beginTour);
		visitPlaces = (Button)findViewById(R.id.visitPlaces);
		beginTour.setOnClickListener(this);
		visitPlaces.setOnClickListener(this);
		
		mSplashThread = new Thread() {
    	public void run() {
    		try {
    			while (splashActive && ms < splashTime || !isButtonClicked) {
    				if(!paused)
    					ms=ms+100;
    				sleep(100);
    			}
    		} catch(Exception e) {}
    		
//    		finish();
//    		Intent intent = new Intent(SplashScreen.this, SharingArtifactsMain.class);
//    		startActivity(intent);
        	}
		};
		mSplashThread.start(); 
	}
	
	@Override
    public boolean onTouchEvent(MotionEvent evt)
    {
    	if(evt.getAction() == MotionEvent.ACTION_DOWN)
    	{
    		synchronized(mSplashThread){
    			mSplashThread.notifyAll();
    		}
    	}
    	return true;
    }
	
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		isButtonClicked = true;
		if(v.getId() == R.id.beginTour) {
			Intent intent = new Intent(SplashScreen.this, SharingArtifactsMain.class);
    		startActivity(intent);
		}
		else if(v.getId() == R.id.visitPlaces) {
			Intent intent = new Intent(SplashScreen.this, VisitPlaces.class);
    		startActivity(intent);
		}		
	}
}
